package com.learn._3stack;

import com.learn.TestTool;
import com.learn._2list.ArrayList;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Random;

public class SimpleStack<T> extends ArrayList<T> implements Stack<T> {


    @Override
    public void push(T obj) {
        add(obj);
    }

    @Override
    public T pop() {
        T res = peek();
        remove(size() - 1);
        return res;
    }

    @Override
    public T peek() {
        return get(size() - 1);
    }

    @Override
    public int size() {
        return super.size();
    }

    public static void main(String[] args) {
        Stack myStack = new SimpleStack();
        java.util.Stack javaStack = new java.util.Stack();
        Stack linkedStack = new LinkedStack();


        int num = 10000000;
        int range = 1000000;
        int circleNum = 100;
        Integer[] array = new Integer[num];
        Random rand = new Random();
        int tmp = 0;
        int tmpNum = num;
        while (tmpNum-- > 0) {
            array[tmp++] = rand.nextInt(range);
        }

      /*  for(Integer i :array){
            javaList.add(i);
            arrayList.add(i);
        */



    //删测试

       /*TestTool.testAndPrintTime(()->

        {
            for (int i = 0; i < num; i++) {
                javaStack.push(i);
            }

            for (int i = 0; i < num; i++) {
                //System.out.println(javaStack.pop());
                javaStack.pop();
            }
            //javaList.clear();
        },1,"java ");*/

    /*   TestTool.testAndPrintTime(()->

        {
        for (int i = 0; i < num; i++) {
            myStack.push(i);
        }

        for (int i = 0; i < num; i++) {
            //System.out.println(myStack.pop());
            myStack.pop();
        }
        //arrayList.clear();
    },1,"my  ");*/

        TestTool.testAndPrintTime(()->

        {
            for (int i = 0; i < num; i++) {
                linkedStack.push(i);
            }

            for (int i = 0; i < num; i++) {
                //System.out.println(myStack.pop());
                linkedStack.pop();
            }
            //arrayList.clear();
        },1,"my  ");









    }
}
